package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.config.annotation.DataScope;
import com.dragon.repository.entity.Repair;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 维修单据表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-12-05
 */
@Mapper
public interface RepairMapper extends BaseMapper<Repair> {


    @Select("select dr.*,dc.name contractName,da.username from dragon_repair dr " +
            "left join dragon_contract dc on dr.contract_id = dc.id " +
            "left join dragon_admin da on dr.admin_id = da.id " +
            "${ew.customSqlSegment}")
    @DataScope(adminAlias = "dr",adminField = "admin_id",deptAlias = "dr",deptField = "department_id",authCodeString = "repair")
    Page<Repair> selectListPage(Page<Repair> page, @Param(Constants.WRAPPER) Wrapper<Repair> wrapper);

    @Select("select dr.*,dc.name contractName,da.username from dragon_repair dr " +
            "left join dragon_contract dc on dr.contract_id = dc.id " +
            "left join dragon_admin da on dr.admin_id = da.id " +
            "where dr.id = #{id}")
    Repair selectDetailById(Integer id);

}
